<!--
 * @Author: wangjian
 * 656876071@qq.com
 * @Date: 2024-09-04 18:12:59
 * @LastEditTime: 2024-09-08 11:39:39
 * @FilePath: src/core/common/component/TableDictCellProp.vue
 * @Description: 
 -->
<script setup lang="ts">
import { onMounted, ref, watch} from "vue";
const props = defineProps(["value","dict"])

const value = props.value
const dictText = ref<string|null>(null)
//如果是字典先加载完成，后渲染数据
onMounted(()=>{
  let dict = props.dict
  console.debug("dict初始化",dict)
  dictLoad(dict)
})
//如果数据已经渲染，后加载的字典数据
watch(()=>props.dict,(newDict)=>{
  console.debug("dict更新了",newDict)
  dictLoad(newDict)
},{deep:true,immediate:true})
// 字典翻译
function dictLoad(dict:[{value:string,label:string}]){
  if(!dict)
    return
  for (let option of dict) {
    if(option.value == value){
      dictText.value = option.label
      break;
    }
  }
}

</script>

<template>
{{ dictText??value}}
</template>

<style scoped>

</style>